package com.zoweunion.mechanic.controller;

import com.zoweunion.mechanic.entity.TSSsVehicleBrandEntity;
import com.zoweunion.mechanic.entity.TSSsVehicleBrandParentEntity;
import com.zoweunion.mechanic.entity.TSSsVehicleModelEntity;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.service.TSSsVehicleBrandParentService;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tsssvehiclebrandparent")
public class TSSsVehicleBrandParentController extends BaseController {
    @Autowired
    private TSSsVehicleBrandParentService tSSsVehicleBrandParentService;

    /**
     * 父级品牌列表
     */
    @GetMapping("/tSSsVehicleBrandParentList")
    public ResponseBean tSSsVehicleBrandParentList(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("sId", getCurrentUser(request).getS_id());
        List<TSSsVehicleBrandParentEntity> list = tSSsVehicleBrandParentService.tSSsVehicleBrandParentList(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }

    /**
     * 机型品牌搜索
     */
    @GetMapping("/tSSsVehicleBrandParentListSearch")
    public ResponseBean tSSsVehicleBrandParentListSearch(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("sId", getCurrentUser(request).getS_id());
        List<TSSsVehicleBrandParentEntity> brandParentList = tSSsVehicleBrandParentService.tSSsVehicleBrandParentList(params);
        List<TSSsVehicleBrandEntity> brandList = tSSsVehicleBrandParentService.tSSsVehicleBrandList(params);
        List<TSSsVehicleModelEntity> modelList = tSSsVehicleBrandParentService.tSSsVehicleModelList(params);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("brandParentList",brandParentList);
        resultMap.put("brandList",brandList);
        resultMap.put("modelList",modelList);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultMap);
    }

    /**
     * 通过父级品牌id获得子品牌名称
     */
    @GetMapping("/tSSsVehicleBrandList")
    public ResponseBean tSSsVehicleBrandList(@RequestParam Map<String, Object> params) throws MyException {
        List<TSSsVehicleBrandEntity> list = tSSsVehicleBrandParentService.tSSsVehicleBrandList(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }

    /**
     * 通过子品牌id获得型号名称
     */
    @GetMapping("/tSSsVehicleModelList")
    public ResponseBean tSSsVehicleModelList(@RequestParam Map<String, Object> params) throws MyException {
        List<TSSsVehicleModelEntity> list = tSSsVehicleBrandParentService.tSSsVehicleModelList(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }

}
